<style lang="less">
</style>
<template>
    <span>
        <Drawer title="时间段" :closable="false" placement="right" v-model="examination" width="45%">
            <Row class="operation">
                <Button @click="add" type="primary" icon="md-add">新增时间段</Button>
                <circleLoading v-if="operationLoading"/>
            </Row>
            <Row style="padding-top: 5px">
                <Table :loading="loading" border :columns="columns" :data="data" ref="userTable"></Table>
            </Row>
            <Row type="flex" justify="end" class="page">
                <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
            </Row>
        </Drawer>
        <timeArrange-drawer ref="timeArrangeDrawer"></timeArrange-drawer>
    </span>
</template>

<script>
    import {selectTimeList,delTimeItem} from "@/api/bus";
    import timeArrangeDrawer from "./timeArrange-drawer";
    export default {
        name: "timeArrange-manage",
        components: {
            timeArrangeDrawer,
        },
        data() {
            return {
                loading: false, // 表单加载状态
                operationLoading: false,
                examination: false,
                drop: false,
                dropDownContent: "展开",
                dropDownIcon: "ios-arrow-down",
                searchForm: {
                    pageNumber: 1, // 当前页数
                    pageSize: 10, // 页面大小
                    sort: "examStartTime", // 默认排序字段
                    order: "asc", // 默认排序方式
                    examseasonId: "",
                },
                columns: [
                    {
                        type: "index",
                        width: 50,
                        align: "center"
                    },
                    {
                        title: "可报名人数",
                        align: "center",
                        key: "signCount"
                    },
                    {
                        title: "已报名人数",
                        align: "center",
                        key: "signlastCount"
                    },
                    {
                        title: "考试日期",
                        align: "center",
                        key: "examTime"
                    },
                    {
                        title: "开始时间",
                        align: "center",
                        key: "examStartTime"
                    },
                    {
                        title: "结束时间",
                        align: "center",
                        key: "examendTime"
                    },
                    {
                        title: "操作",
                        key: "action",
                        align: "center",
                        render: (h, params) => {
                            return h("div", [
                                h(
                                    "Button",
                                    {
                                        props: {
                                            type: "primary",
                                            size: "small"
                                        },
                                        style: {
                                            marginRight: "5px"
                                        },
                                        on: {
                                            click: () => {
                                                this.edit(params.row);
                                            }
                                        }
                                    },
                                    "编辑"
                                ),
                                h(
                                    "Button",
                                    {
                                        props: {
                                            type: "error",
                                            size: "small"
                                        },
                                        on: {
                                            click: () => {
                                                this.remove(params.row);
                                            }
                                        }
                                    },
                                    "删除"
                                )
                            ]);
                        }
                    }],
                data: [], // 表单数据
                total: 0 // 表单数据总数
            }
        },
        methods: {
            showDrawer(params){
                this.examination = true;
                if (params.examseasonId) {
                    this.searchForm.examseasonId = params.examseasonId;
                    this.getDataList();
                }
            },
            getDataList() {
                this.loading = true;
                selectTimeList(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.status === true) {
                        this.data = res.data.rows;
                        this.total = res.data.total;
                        console.info(this.data)
                    }
                });
            },
            //设置发布状态
            edit(v) {
                this.$refs.timeArrangeDrawer.showDrawer(v);
            },
            add() {
                let query = {examseasonId: this.searchForm.examseasonId}
                this.$refs.timeArrangeDrawer.showDrawer(query);
            },
            remove(v){
                this.$Modal.confirm({
                    title: "确认删除",
                    content: "您确认要删除该条件吗?",
                    onOk: () => {
                        delTimeItem(v.id).then(res => {
                            if (res.status === true) {
                                this.$Message.success("删除成功");
                                this.getDataList();
                            }
                        });
                    }
                });
            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "展开";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getDataList();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getDataList();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getDataList();
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
        },
        mounted() {
        }
    }
</script>
